package com.aires.testbeandefinitionregistrypostprocessor;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.stereotype.Component;

/**
 * @program: spring
 * @description: BeanDefinitionRegistryPostProcessor extends BeanFactoryPostProcessor
 * 				 BeanDefinitionRegistryPostProcessor再bean定义还没有加载前
 * @author: fan zhengxiang
 * @create: 2020-11-02 21:03
 */
@Component
public class AiresBeanDefinitionRegistryPostProcessor implements BeanDefinitionRegistryPostProcessor {
	@Override
	public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException {
		System.out.println("AiresBeanDefinitionRegistryPostProcessor的postProcessBeanDefinitionRegistry方法执行了");
		System.out.println("bean定义的数量:"+registry.getBeanDefinitionCount());

		RootBeanDefinition rootBeanDefinition = new RootBeanDefinition(AiresRegistry.class);
		registry.registerBeanDefinition("airesRegistry",rootBeanDefinition);

	}

	@Override
	public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
		System.out.println("AiresBeanDefinitionRegistryPostProcessor的postProcessBeanFactory方法执行了");
		System.out.println("bean定义的数量:"+beanFactory.getBeanDefinitionCount());

	}
}